﻿using System;
using System.Web.SessionState;

using OurCouse.WebApp.Proxy;

namespace OurCouse.WebApp
{
	/// <summary>
	/// 网站首页
	/// </summary>
    public partial class Default : System.Web.UI.Page
    {
		/// <summary>
		/// 页面加载函数
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
			if (!String.IsNullOrEmpty(((string)Session["username"])))
			{
				this._welcomeWords.Text = "欢迎您，" + (string)Session["username"];
				this._myLoginCtrl.Visible = false;
			}

			// 添加登录事件
			this._myLoginCtrl.LoginEvent += new EventHandler(this._myLoginCtrl_LoginEvent);
        }

		/// <summary>
		/// 登录事件函数
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void _myLoginCtrl_LoginEvent(object sender, EventArgs e)
		{
			// 获取用户名和密码
			string userName = this._myLoginCtrl.UserName;
			string userPass = this._myLoginCtrl.UserPass;

			// 验证登录结果
			bool loginOK = (new RegUserDBTaskProxy()).UserLogin(userName, userPass);

			if (loginOK)
			{
				Session["username"] = this._myLoginCtrl.UserName;
				this._welcomeWords.Text = "欢迎您，" + userName;
				this._myLoginCtrl.Visible = false;
			}
			else
			{
				this._welcomeWords.Text = "对不起，用户名或密码错误";
			}
		}
    }
}
